package factory.simpleFactory;

import factory.simpleFactory.pizza.AbstractPizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author zhouyang
 * @projectName DesignMode_Java
 * @description: TODO
 * @date 2019/5/25 19:55
 */
public class PizzaStore {
    private PizzaFactory pizzaFactory;

    public PizzaStore(PizzaFactory pizzaFactory) {
        setFactory(pizzaFactory);
    }

    public void setFactory(PizzaFactory absFactory){
        AbstractPizza abstractPizza = null;
        String orderType;
        this.pizzaFactory = absFactory;
        do {
            orderType = getType();//获取用户输入
            abstractPizza = absFactory.createPizza(orderType);//创建这个实例
            abstractPizza.prepare();
            abstractPizza.bake();
            abstractPizza.cut();
            abstractPizza.box();
        }while (true);
    }

    private String getType(){
        String type = null;
        try {
            BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input pizza type");
            type = strin.readLine();

        }catch (Exception e){
            e.printStackTrace();
        }
        return type;
    }
}
